What is caw?
The 'caw' npm package is a utility for handling HTTP/HTTPS proxies in Node.js. It simplifies the process of making HTTP requests through proxies, which can be useful for various purposes such as web scraping, testing, and accessing geo-restricted content.
What are caw's main functionalities?
Proxy HTTP Requests
This feature allows you to make HTTP requests through a proxy. The code sample demonstrates how to use 'caw' with the 'got' library to make a request to an API endpoint through a proxy.
const caw = require('caw');
const got = require('got');
(async () => {
const proxy = caw();
const response = await got('https://api.ipify.org?format=json', { agent: { https: proxy } });
console.log(response.body);
})();
Custom Proxy Configuration
This feature allows you to configure custom proxy settings. The code sample shows how to specify a custom proxy server with 'caw' and use it to make an HTTP request.
const caw = require('caw');
const got = require('got');
(async () => {
const proxy = caw({ protocol: 'http', hostname: 'proxy.example.com', port: 8080 });
const response = await got('https://api.ipify.org?format=json', { agent: { https: proxy } });
console.log(response.body);
})();
Automatic Proxy Detection
This feature allows 'caw' to automatically detect and use the system's proxy settings. The code sample demonstrates how to make an HTTP request using the system's proxy configuration.
const caw = require('caw');
const got = require('got');
(async () => {
const proxy = caw();
const response = await got('https://api.ipify.org?format=json', { agent: { https: proxy } });
console.log(response.body);
})();
Other packages similar to caw
proxy-agent
'proxy-agent' is a similar package that provides a unified API for different types of proxy agents (HTTP, HTTPS, SOCKS, etc.). It is more versatile in terms of the types of proxies it supports compared to 'caw'.
global-agent
'global-agent' allows you to globally configure HTTP/HTTPS proxies for all HTTP requests in a Node.js application. It is useful for applications that need to enforce proxy usage globally, unlike 'caw' which is used on a per-request basis.
tunnel
'tunnel' is a package that provides HTTP/HTTPS proxy tunneling. It is more focused on tunneling capabilities and supports various proxy protocols, making it a more specialized tool compared to 'caw'.
caw
Construct HTTP/HTTPS agents for tunneling proxies
Install
$ npm install --save caw
Usage
var caw = require('caw');
var got = require('got');
got('todomvc.com', {
agent: caw()
}, function () {});
API
caw(proxy, options)
proxy
Type: string
Proxy URL.
options
Type: object
Besides the options below, you can pass in options allowed in tunnel-agent.
protocol
Type: string
Default: http
Endpoint protocol.
License
MIT © Kevin Mårtensson